﻿<UserControl x:Class="SharePointCommander.SCPropertySheet"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:WPFToolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit" 
             xmlns:SPC="clr-namespace:SharePointCommander"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    
    <ListView x:Name="ListView" Margin="3,0,0,0" Grid.Column="1" ItemsSource="{Binding}">
        
        <ListView.Resources>
            <DataTemplate x:Key="DataTemplateText">
                <TextBox Text="{Binding Path=Value, Mode=TwoWay}" BorderThickness="0,0,0,0" IsReadOnly="{Binding Path=ReadOnly}" ToolTip="{Binding Path=Value, Mode=OneWay}" />
            </DataTemplate>
            <DataTemplate x:Key="DataTemplateCheckbox">
                <CheckBox IsChecked="{Binding Path=Value, Mode=TwoWay}" BorderThickness="0,0,0,0" IsEnabled="{Binding Path=ReadWrite}" ToolTip="{Binding Path=Value, Mode=OneWay}" />
            </DataTemplate>
            <DataTemplate x:Key="DataTemplateCombobox">
                <ComboBox SelectedValue="{Binding Path=Value, Mode=TwoWay}" ItemsSource="{Binding Choices}" BorderThickness="0,0,0,0" IsReadOnly="{Binding Path=ReadOnly}" ToolTip="{Binding Path=Value, Mode=OneWay}" />
            </DataTemplate>
            <DataTemplate x:Key="DataTemplateDatetime">
                <WPFToolkit:DatePicker SelectedDate="{Binding Path=Value, Mode=TwoWay}" IsEnabled="{Binding Path=ReadWrite}" ToolTip="{Binding Path=Value, Mode=OneWay}" />
            </DataTemplate>
            <DataTemplate x:Key="DataTemplateArray">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition Width="20" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="{Binding Path=Value, Mode=OneWay}" ToolTip="{Binding Path=Value, Mode=OneWay}" Grid.Column="0" VerticalAlignment="Center" />
                    <Button Content="..." Grid.Column="1" />
                </Grid>
            </DataTemplate>
            <DataTemplate x:Key="DataTemplateException">
                <TextBlock Foreground="Red" Text="{Binding Path=Value.Message, Mode=OneWay}" ToolTip="{Binding Path=Value.Message, Mode=OneWay}" />
            </DataTemplate>
            <DataTemplate x:Key="DataTemplateValueType">
                <TextBlock Text="{Binding Path=ValueType, Mode=OneWay}" ToolTip="{Binding Path=ValueType, Mode=OneWay}" />
            </DataTemplate>
            <DataTemplate x:Key="DataTemplateGuid">
                <TextBlock Text="{Binding Path=Value, Mode=OneWay}" ToolTip="{Binding Path=Value, Mode=OneWay}" />
            </DataTemplate>
            <DataTemplate x:Key="DataTemplateObject">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition Width="20" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="{Binding Path=Value, Mode=OneWay}" ToolTip="{Binding Path=Value, Mode=OneWay}" Grid.Column="0" />
                    <Button x:Name="btnOpenObject" Content="..." Grid.Column="1" Click="btnOpenObject_Click" />
                </Grid>
            </DataTemplate>
            <SPC:PropertyValueSelector x:Key="PropertyValueSelector"/>
        </ListView.Resources>
        
        <ListView.ItemContainerStyle>
            <Style TargetType="ListViewItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                <Setter Property="VerticalContentAlignment" Value="Center" />
                <Setter Property="BorderThickness" Value="0,0,0,1" />
                <Setter Property="BorderBrush" Value="Gray" />
                <Setter Property="Height" Value="24" />
            </Style>
        </ListView.ItemContainerStyle>
        
        <ListView.View>
            <GridView>
                <GridViewColumn Width="150" Header="Name" DisplayMemberBinding="{Binding Name}" />
                <GridViewColumn Width="200" Header="Value" CellTemplateSelector="{DynamicResource PropertyValueSelector}" />
                <GridViewColumn Width="150" Header="Type" CellTemplate="{DynamicResource DataTemplateValueType}" />
            </GridView>
        </ListView.View>
        
    </ListView>
    
</UserControl>
